<% admin_layout "full-width" %>

<% admin_breadcrumb(plural_resource_name(Spree::Product)) %>

<% content_for :page_actions do %>
  <li id="new_product_link">
    <%= button_link_to Spree.t(:new_product), new_object_url, { :remote => true, :id => 'admin_new_product' } %>
  </li>
<% end if can?(:create, Spree::Product) %>

<% content_for :table_filter_title do %>
  <%= Spree.t(:search) %>
<% end %>

<% content_for :table_filter do %>
  <div data-hook="admin_products_sidebar">
    <%= search_form_for [:admin, @search] do |f| %>
        <%- locals = {:f => f} %>
        <div class="row" data-hook="admin_products_index_search" >
          <div class="col-xs-6">
            <div class="field">
              <%= f.label :name_cont, Spree::Product.human_attribute_name(:name) %>
              <%= f.text_field :name_cont, :size => 15 %>
            </div>
          </div>

          <div class="col-xs-4">
            <div class="field">
              <%= f.label :variants_including_master_sku_cont, Spree::Variant.human_attribute_name(:sku) %>
              <%= f.text_field :variants_including_master_sku_cont, :size => 15 %>
            </div>
          </div>

          <div class="col-xs-2">
            <div class="field checkbox">
              <label>
                <%= f.check_box :deleted_at_null, {:checked => params[:q][:deleted_at_null] == '0'}, '0', '1' %>
                <%= Spree.t(:show_deleted) %>
              </label>
            </div>
          </div>
        </div>

        <div class="actions filter-actions" data-hook="admin_products_index_search_buttons">
          <%= button Spree.t(:search) %>
        </div>
    <% end %>
  </div>
<% end %>

<div id="new_product_wrapper" data-hook></div>

<%= paginate @collection, theme: "solidus_admin" %>

<% if @collection.any? %>
  <table class="index" id="listing_products">
    <colgroup>
       <col style="width: 15%;">
       <col style="width: 10%;">
       <col style="width: 48%;">
       <col style="width: 10%;">
       <col style="width: 17%;">
    </colgroup>
    <thead>
      <tr data-hook="admin_products_index_headers">
        <th><%= Spree::Variant.human_attribute_name(:sku) %></th>
        <th colspan="2"><%= sort_link @search,:name, Spree::Product.human_attribute_name(:name), { :default_order => "desc" }, {:title => 'admin_products_listing_name_title'} %></th>
        <th><%= sort_link @search,:master_default_price_amount, Spree::Product.human_attribute_name(:price), {}, {:title => 'admin_products_listing_price_title'} %></th>
        <th data-hook="admin_products_index_header_actions" class="actions"></th>
      </tr>
    </thead>
    <tbody>
      <% @collection.each do |product| %>
          <tr <%== "style='color: red;'" if product.deleted? %> id="<%= spree_dom_id product %>" data-hook="admin_products_index_rows" class="<%= cycle('odd', 'even') %>">
            <td class="align-center"><%= product.sku %></td>
            <td class="align-center"><%= image_tag product.display_image.attachment(:mini) %></td>
            <td><%= link_to product.try(:name), edit_admin_product_path(product) %></td>
            <td class="align-center"><%= product.display_price.to_html %></td>
            <td class="actions" data-hook="admin_products_index_row_actions">
              <%= link_to_edit product, :no_text => true, :class => 'edit' if can?(:edit, product) && !product.deleted? %>
              &nbsp;
              <%= link_to_clone product, :no_text => true, :class => 'clone' if can?(:clone, product) %>
              &nbsp;
              <%= link_to_delete product, :no_text => true if can?(:delete, product) && !product.deleted? %>
            </td>
          </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <div class="col-xs-9 no-objects-found">
    <%= render 'spree/admin/shared/no_objects_found',
                  resource: Spree::Product,
                  new_resource_url: new_object_url %>
  </div>
<% end %>

<%= paginate @collection, theme: "solidus_admin" %>
